<?php
class ArtController extends Controller
{
	function show()
    {
		$list	=	Article::getList(null);

		$this->assign('list',	$list);
		$this->display();
    }
    
    /**
     * 请一篇文章
     */
	function r()
    {
		$aid	=	fetch_get('id', 'int');
		$art	=	Article::get($aid);
		if(!$art)
		{
			Show::warning('no such article', 'arts');
		}
		
		$talks	=	TalkHelper::listFor(MODEL_ARTICLE, $aid);
		UserHelper::patch($talks);

		$this->assign('article', $art);
		$this->assign('talks',	$talks);
		
		$this->display();
    }
    
    /**
     * 写谈论
     */
    function talk()
    {
    	//只有登陆用户才能写谈论
    	//以后做UE优化时做到js里做登陆后才能发表的检查
    	UserAuthHelper::authenticate();
    	
    	$aid	=	fetch_get('id', 'int');
    	$title	=	fetch_post('title');
    	$body	=	fetch_post('content');
    	
    	if(!Article::existing($aid))
    	{
    		Show::warning('无此文章记录');
    	}
    	if(!$body)
    	{
    		Show::warning('请填写谈论内容');
    	}
    	
    	if(TalkHelper::addFor(MODEL_ARTICLE, $aid, UserAuthHelper::uid(), $body, $title))
    	{
    		Show::notice('添加谈论内容成功');
    	}
    	else
    	{
    		Show::warning('添加谈论内容失败，请稍候再试');
    	}
    }
    
}
?>